using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

namespace Demo02.Controllers;

[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{

    private IOptions<BookOption> bookOption;
    public TestController(IOptions<BookOption> bookOption)
    {
        this.bookOption = bookOption;
    }


    
    /// <summary>
    /// 测试接口1
    /// </summary>
    /// <returns></returns>
    [HttpGet] 
    public string test1()
    {
       // this.HttpContext.Request.Headers
        
        this.HttpContext.Response.Cookies.Append("test","1234");
        return "test";
    }
    
    
    /// <summary>
    /// 测试接口2
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    [HttpPost]
    public string Get(User user)
    {
        return bookOption?.Value?.Name +user.UserName;
    }
    // private static readonly string[] Summaries = new[]
    // {
    //     "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    // };
    //
    // private readonly ILogger<WeatherForecastController> _logger;
    //
    // public WeatherForecastController(ILogger<WeatherForecastController> logger)
    // {
    //     _logger = logger;
    // }
    //
    // [HttpGet(Name = "GetWeatherForecast")]
    // public IEnumerable<WeatherForecast> Get()
    // {
    //     return Enumerable.Range(1, 5).Select(index => new WeatherForecast
    //         {
    //             Date = DateTime.Now.AddDays(index),
    //             TemperatureC = Random.Shared.Next(-20, 55),
    //             Summary = Summaries[Random.Shared.Next(Summaries.Length)]
    //         })
    //         .ToArray();
    // }
}